package com.sjm.bookshop.service.userservice;

import com.sjm.bookshop.dao.LoginDao;
import com.sjm.bookshop.entity.User;
import com.sjm.bookshop.utils.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
@Transactional
public class UserService {
    @Autowired
    private LoginDao loginDao;

    //查询用户列表
    public List<User> userList() {
        return loginDao.selectLists();
    }

    //    模糊查询
    public List<User> selectSomeOne(String keyWord) {
        return loginDao.selectSomeOneLike(keyWord);
    }

    //    删除用户
    public Integer deleteOne(int id) {
        return loginDao.delete(id);
    }

    //    修改状态
    public int changeUserStatus(Integer isLocked, Integer id) {
        return loginDao.change(isLocked, id);
    }

    //    修改用户
    public int UpdateUserInfo(User user) {
        //           去除密码的空格
        String[] s = user.getPassword().split(" ");
        String password = "";
        for (int i = 0; i < s.length; i++) {
            password += password;
        }
        user.setPassword(MD5Util.MD5(password));
        user.setUpdatedtime(new Date());
        return loginDao.updateInfo(user);
    }
}
